package descentFly.app.dialogs.levelsWindow
{
	import UIFree.controls.base.uif_previewSource;
	import UIFree.uif_component;
	
	import away3d.vf.utils;
	
	import descentFly.app.df_block;
	import descentFly.app.df_component;
	import descentFly.app.df_label;
	import descentFly.server.df_servers;
	
	import flash.geom.Rectangle;
	
	public class df_levelItem extends df_listItemImage {
		public static const HEIGHT: int = 100;
		private var _name			: df_label;
		private var _description	: df_label;
		
		public function df_levelItem(parent:uif_component, ax:int=0, ay:int=0, awidth:int=0, item: Object=null, a_styleClass:Object='block') {
			super(parent, ax, ay, awidth, HEIGHT, item, a_styleClass);
			_name.text 			= _data.name;
			_description.text 	= _data.description;
		}
		
		override protected function get previewRect(): Rectangle {
			var inner: Rectangle = layer.getInner();
			inner.width = inner.height / 0.66;
			return inner;
		}
		
		override protected function createComponents(a_layer:df_component, inner:Rectangle):void {
			super.createComponents(a_layer, inner);
			var inner: Rectangle = getInner();
			inner.left = previewRect.right + getSpace(true);
			_name			= new df_label(a_layer, inner.x, inner.y, inner.width, 26, 'levelTitle');
			inner.top 		+= _name.height;
			_description 	= new df_label(a_layer, inner.x, inner.y, inner.width, inner.height, 'levelDescription');
		}
		
		override protected function get previewURL(): String {
			var relativeFilePath: String = 'levels/preview/' + _data.id + '_90.jpg';
			if (_data.urlPattern) {
				return Utils.sprintf(_data.urlPattern, relativeFilePath);
			} else return df_servers.DATA_URL + '/' + relativeFilePath;
		}
	}
}